import Taro from "@tarojs/taro";

export const checkRecordPermission = (permissionScope = "",permissionName='') => {
  if (!permissionScope) {
    return;
  }
  Taro.getSetting({
    success(res) {
      if (!res.authSetting["scope.record"]) {
        Taro.authorize({
          scope: "scope.record",
          success() {
            // 用户已同意授权
            console.log("用户已同意授权");
          },
          fail() {
            // 用户拒绝了授权
            console.log("用户拒绝了授权");
            Taro.showModal({
              title: "提示",
              content: "需要获取录音权限，请点击确定进入设置页面进行授权。",
              showCancel: false,
              success(res) {
                if (res.confirm) {
                  Taro.openSetting({
                    success(res) {
                      console.log(res.authSetting);
                      // 用户在设置页面设置了录音权限
                      if (res.authSetting["scope.record"]) {
                        console.log("用户在设置页面设置了录音权限");
                      } else {
                        console.log("用户在设置页面未设置录音权限");
                      }
                    },
                  });
                }
              },
            });
          },
        });
      } else {
        // 已经有权限
        console.log("已经有录音权限");
      }
    },
  });
};
